package com.itheima.service.impl;

import com.itheima.dao.BookDao;
import com.itheima.exception.BusinessException;
import com.itheima.pojo.Book;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    public boolean save(Book book) {

        return bookDao.save(book)!=0;
    }

    public boolean update(Book book) {

        return bookDao.update(book)!=0;

    }

    public boolean delete(Integer id) {

        return bookDao.delete(id)!=0;

    }

    public Book getById(Integer id) {
        //书写一定的业务异常逻辑
        if(id<0){
            //new 创建异常
            //throw 抛出异常
           throw new BusinessException("对不起,你的id不能为负数!");
        }
        return bookDao.getById(id);
    }

    public List<Book> getAll() {
        return bookDao.getAll();
    }
}
